package com.haorui.lygyd.wxapi.service;

import com.haorui.base.core.exception.BusinessException;
import com.haorui.base.system.enumerate.MubanLable;
import com.haorui.base.system.enumerate.MubanLeibie;
import com.haorui.lygyd.employeemanager.entity.MemberEntity;
import com.haorui.lygyd.wxapi.dto.WXMemberForgetDto;
import com.haorui.lygyd.wxapi.dto.WXMemberLoginDto;
import com.haorui.lygyd.wxapi.dto.WXMemberRegisDto;
import com.haorui.lygyd.wxapi.dto.WXMemberUpdatePassDto;
import com.haorui.lygyd.wxapi.entity.WXUserInfoEntity;
import com.haorui.sms.common.SMSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 郭飞
 * @version 1.0
 * @project znsm
 * @package com.haorui.wxapi.service
 * @createDate 2017/10/15 0015 18:17
 * @modfiyDate
 * @function
 */
@Service
@Slf4j
public class WXMemberService {
    @Autowired
    private WXPublicService wxPublicService;

    /***
     *微信接口方法
     *查询单个会员详细信息
     * @return
     */
    public MemberEntity wxselectMemberDetail() throws BusinessException {
        return wxPublicService.selectMemberDetail();
    }

    /***
     *微信接口方法
     *会员登录
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public MemberEntity wxlogin(WXMemberLoginDto dto) throws BusinessException {
        return wxPublicService.login(dto);

    }

    /***
     *微信接口方法
     *会员注册
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public MemberEntity wxzhuCe(WXMemberRegisDto dto) throws BusinessException {
        return wxPublicService.zhuCe(dto);

    }

    /***
     *微信接口方法
     *忘记密码确认登录
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public MemberEntity wxforgetMiMa(WXMemberForgetDto dto) throws BusinessException {
        return wxPublicService.forgetMiMa(dto);
    }


    /***
     * 微信接口方法
     * 修改密码确认登录
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public MemberEntity updatePass(WXMemberUpdatePassDto dto) throws BusinessException {
        return wxPublicService.updatePass(dto);
    }

    /***
     *微信接口方法
     *获取验证码
     * @param shoujihao
     * @return
     */
    public void wxgetYanZhengMa(String shoujihao) throws BusinessException {
        int mes = 100000 + (int) (Math.random() * (99999 - 10000 + 1));
        Map<MubanLable, String> parm = new HashMap<MubanLable, String>();
        parm.put(MubanLable.YZM, mes + "");
        SMSUtil.sendMsg(shoujihao, MubanLeibie.YZM, parm);
    }

    /**
     * 微信接口方法
     * 会员修改密码
     *
     * @param dto
     * @return MemberEntity
     */
    public MemberEntity wxmemberUpdatePass(WXMemberUpdatePassDto dto) throws BusinessException {
        return wxPublicService.memberUpdatePass(dto);
    }

    /***
     * 根据推荐人卡号查询推荐人
     * @param memberKaHao
     * @return
     */
    public MemberEntity findMemberByShouJiHaoMa(String memberKaHao) {
        return wxPublicService.findMemberByShouJiHaoMa(memberKaHao);
    }

    /**
     * 验证验证码
     *
     * @return
     */
    public boolean checkYanzhengma(String shoujihaoma, String yanzhengma) {
        return wxPublicService.checkYanzhengma(shoujihaoma, yanzhengma);
    }

    /***
     * 验证密码是否正确
     * @param miMa
     * @return
     */
    public boolean checkByMemberMiMaAndId(String miMa) throws BusinessException {
        return wxPublicService.checkByMemberMiMaAndId(miMa);
    }

    /**
     * 用户头像
     *
     * @return
     */
    public WXUserInfoEntity getPhotoWeixin() throws BusinessException {
        return wxPublicService.getPhotoWeixin();
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public long getcurrentDate() {
        return wxPublicService.getcurrentDate();
    }
}
